/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cxhd.lis.model.newmodel;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;
import java.util.List;

/**
 *
 * @author cxhd
 */
@SuppressWarnings("serial")
public class lisKsdm extends Model<lisKsdm> {
      public static final lisKsdm lisKsdmdao=new lisKsdm();
     
    public void deleteKsdm(int PK) throws Exception{
        Db.use("mysql").update("delete from lis_ksdm where PK="+PK);

    }
    public void addKsdm(Controller con) throws Exception{
 
             set("KSDM", getKsdm())
                .set("KSMC", con.getPara("KSMC"))
                .set("SRM1", con.getPara("SRM1"))
                .save();
               
    }
    public void updateKsdm(Controller con){
        System.out.println(con.getPara("PK"));
        findById(con.getPara("PK"))
                .set("KSMC", con.getPara("KSMC"))
                .set("SRM1",  con.getPara("SRM1"))
                .update();
    }
    public String getKsdm(){
         List<Record> list=Db.use("mysql").find("select * from lis_ksdm limit 0,10");
        String  value = "1";
        if(list.size()>0){
       value = (Integer.parseInt(Db.use("mysql").findFirst("SELECT MAX(KSDM) as id from lis_ksdm ").get("id") + "") + 1) + "";
        }
      return value;
    }
}
